package com.yunxi.controller.activiti;


import com.yunxi.activiti.pojo.ActivitiManageVO;
import com.yunxi.activiti.service.ActivitiManageDubboService;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/flowRun")
@Api(tags = "activiti:run", description = "工作流运行接口")
public class ActivitiRunController {
    private static final Logger logger = LoggerFactory.getLogger(ActivitiRunController.class);

   @Autowired
   private ActivitiManageDubboService activitiManageDubboService;

    @PostMapping(value = "/start")
    @ApiOperation(value = "启动流程")
    public ApiResult start(@RequestBody ActivitiManageVO  am, @CurrentUser LoginInfo user) throws Exception {
        return  activitiManageDubboService.start(am,user);
    }

    @PostMapping(value = "/next")
    @ApiOperation(value = "下一步")
    public ApiResult next(@RequestBody ActivitiManageVO  am,@CurrentUser LoginInfo user) throws Exception {
        return  activitiManageDubboService.next(am,user);
    }

    @GetMapping(value = "/pageWait")
    @ApiOperation(value = "查询待办")
    public ApiResult pageWait(ActivitiManageVO  am,@CurrentUser LoginInfo user) throws Exception {
        return  activitiManageDubboService.pageWait(am,user);
    }

    @PostMapping(value = "/last")
    @ApiOperation(value = "上一步")
    public ApiResult last(@RequestBody ActivitiManageVO  am,@CurrentUser LoginInfo user) throws Exception {
        return  activitiManageDubboService.last(am,user);
    }

    @PostMapping(value = "/del")
    @ApiOperation(value = "删除流程")
    public ApiResult del(@RequestBody ActivitiManageVO  am,@CurrentUser LoginInfo user) throws Exception {
         activitiManageDubboService.stopActivitiByBusinessKey(am.getBusinessKey());
         return ResponseUtil.ok();
    }

    @GetMapping(value = "/listRecordByBusinessKey")
    @ApiOperation(value = "删除流程")
    public ApiResult listRecordByBusinessKey(String businessKey,@CurrentUser LoginInfo user) throws Exception {
        return ResponseUtil.ok(activitiManageDubboService.listRecordByBusinessKey(businessKey));
    }

    @GetMapping(value = "/listRecord")
    @ApiOperation(value = "删除流程")
    public ApiResult listRecordByInstanceId(String instanceId,@CurrentUser LoginInfo user) throws Exception {
        return ResponseUtil.ok(activitiManageDubboService.listRecordByInstanceId(instanceId));
    }
}
